package com.example.itemreader.base;

import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.NonTransientResourceException;
import org.springframework.batch.item.ParseException;
import org.springframework.batch.item.UnexpectedInputException;

import java.util.Iterator;
import java.util.List;

/**
 * 自定义ItemReader
 *
 * @author XieYa
 */
public class MyReader implements ItemReader<String> {

    private final Iterator<String> iterator;

    public MyReader(List<String> list) {
        this.iterator = list.iterator();
    }

    @Override
    public String read() throws UnexpectedInputException, ParseException, NonTransientResourceException {
        //默认一个一个读数据
        if (iterator.hasNext()) {
            return this.iterator.next();
        } else {
            return null;
        }
    }
}
